import { HttpException, HttpStatus } from "@nestjs/common";

// * 验证账号信息
interface AccountType {
  nickname: string;
  password: string;
}
export default function ({ nickname, password }: AccountType): Promise<void> {
  return new Promise(resolve => {
    if (!nickname || !password) {
      const message = nickname ? "密码是必填项" : "用户名是必填项";
      throw new HttpException(message, HttpStatus.BAD_REQUEST);
    }
    if (nickname.length < 3 || nickname.length > 16) {
      throw new HttpException("用户名的长度最小为3,最大为16", HttpStatus.BAD_REQUEST);
    }
    if (password.length < 6 || password.length > 16) {
      throw new HttpException("密码的长度最小为6,最大为16", HttpStatus.BAD_REQUEST);
    }
    resolve();
  });
}
